<template>
  <el-row>
    <el-col :span="24">
      <el-card class="search-form">
        <el-form ref="searchForm" class="el-form-col el-form-s" :model="search">
          <el-row :gutter="15">
            <el-col :lg="4" :md="6">
              <el-form-item prop="orderNo" >
                <el-input v-model="search.orderNo" type="textarea" :rows="4" clearable
                          placeholder="关联订单号  (支持多单查询，用英文逗号分隔)"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="consigneName">
                <el-input v-model="search.consigneName" placeholder="客户姓名" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item prop="cargoOwner">
                <el-input v-model="search.cargoOwner" placeholder="商家名称" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item>
                <el-row class="search-btns" :gutter="5">
                  <el-col :span="12">
                    <el-button type="primary" :loading="searchLoading" plain native-type="submit" @click.prevent="searchFunc(search)"><span>搜索</span></el-button>
                  </el-col>
                  <el-col :span="12">
                    <el-button @click="resetFields('searchForm')" plain>重置</el-button>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
    </el-col>
    <el-col :span="24">
      <BasicTable
        ref="BasicTable"
        url="/ms-terminal-order/ch-arrive/get-arrive-list"
        :tabs="tabs"
        :columns="columns">
        <template slot="preColumn">
          <el-table-column prop="orderNo" fixed="left" width="155px" align="center" label="关联单号">
            <template slot-scope="scope">
              <a href="javascript:;" class="blue-color" @click="showOrder(scope.row)">{{ scope.row.orderNo }}</a>
            </template>
          </el-table-column>
        </template>
        <template slot="column">
          <el-table-column fixed="right" width="100px" align="center" label="操作" v-if="state == 0 || state == 1">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="showDetail(scope.row)"
              >
                确认到件
              </el-button>
            </template>
          </el-table-column>
          <el-table-column fixed="right" width="100px" align="center" label="操作" v-if="state == 2">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="showDetail(scope.row)"
              >
                详情
              </el-button>
            </template>
          </el-table-column>
        </template>
      </BasicTable>
    </el-col>
  </el-row>
</template>
<script>
import {unixTimestampFilter, filterDataBaseDictionary} from '@/filters'
import {copy} from '@/utils'
export default {
  name: 'arriveManager',
  data() {
    let columns = [
      {
        label: '客户姓名',
        width: '80px',
        data: 'consigneName'
      },
      {
        label: '客户电话',
        width: '100px',
        data: 'consignePhone'
      },
      {
        label: '关联订单类型',
        width: '100px',
        data: 'orderType',
        render(data, full) {
          return filterDataBaseDictionary(data)
        }
      },
      {
        label: '入库仓',
        data: 'warehouse'
      },
      {
        label: '仓储类型',
        width: '100px',
        data: 'storageType',
        render(data, full) {
          return filterDataBaseDictionary(data)
        }
      },
      {
        label: '商家名称',
        data: 'cargoOwner'
      },
      {
        label: '录入商品总数',
        width: '100px',
        data: 'totalProduct',
        render(data, full) {
          if (full.orderType === 'STORAGEORDERTYPE02') {
            return `/`
          }
          return data
        }
      },
      {
        label: '总包件',
        width: '82px',
        data: 'totalPackage'
      },
      {
        label: '录单员',
        data: 'placeUserName'
      },
      {
        label: '录单时间',
        width: '134px',
        data: 'foundTime',
        render(data, full) {
          return unixTimestampFilter(data, 'YYYY-MM-DD HH:mm')
        }
      }
    ]
    let secondColumns = copy(columns, true)
    secondColumns.splice(secondColumns.length - 3, 1, {
      label: '录入总包件',
      data: 'totalPackage'
    }, {
      label: '到件商品总数',
      data: 'totalArriveNum',
      render(data, full) {
        if (full.orderType === 'STORAGEORDERTYPE02') {
          return `/`
        }
        return data
      }
    }, {
      label: '到件包件总数',
      data: 'arrivePackageNum'
    })
    let thirdColumns = copy(columns, true)
    thirdColumns.splice(thirdColumns.length - 3, 1, {
      label: '录入包件总数',
      data: 'totalPackage'
    }, {
      label: '到件商品总数',
      data: 'totalArriveNum',
      render(data, full) {
        if (full.orderType === 'STORAGEORDERTYPE02') {
          return `/`
        }
        return data
      }
    }, {
      label: '到件包件总数',
      data: 'arrivePackageNum'
    })
    return {
      state: 0,
      isOpen: false,
      visible: false,
      searchLoading: false,
      search: {
        orderNo: '',
        consigneName: '',
        cargoOwner: ''
      },
      columns,
      tabs: [
        {
          label: '未收货',
          callback: (params) => {
            params.arriveState = '0'
            this.state = 0
          }
        },
        {
          label: '部分收货',
          callback: (params) => {
            params.arriveState = '1'
            this.state = 1
          },
          columns: secondColumns
        },
        {
          label: '已收货',
          callback: (params) => {
            params.arriveState = '2'
            this.state = 2
          },
          columns: thirdColumns
        }
      ],
      typeArr: [],
      item: {}
    }
  },
  created() {
  },
  methods: {
    // 搜索
    searchFunc(search) {
      const basicTable = this.$refs.BasicTable
      if (basicTable) {
        let params = copy(search)
        this.searchLoading = true
        basicTable.search(params).finally(_ => {
          this.searchLoading = false
        })
      }
    },
    // 重置表单
    resetFields() {
      const searchForm = this.$refs.searchForm
      if (searchForm) {
        searchForm.resetFields()
      }
    },

    // 表格刷新
    refresh() {
      this.searchFunc(this.search)
    },
    showOrder(data) {
      this.$router.push({path: '/ss-oms/orders/arrive-manager/show/' + data.orderId})
    },
    // 跳转详情
    showDetail(data) {
      this.$router.push({path: '/ss-oms/orders/arrive-manager/arrive/' + data.orderId, query: {state: this.state, orderType: data.orderType}})
    }
  }
}
</script>
